package rs.fon.is.music.services;

import java.util.LinkedList;
import java.util.List;

import rs.fon.is.music.domain.MusicAlbum;
import rs.fon.is.music.domain.MusicGroup;
import rs.fon.is.music.domain.MusicRecording;
import rs.fon.is.music.persistence.DataModelManager;

public class MusicServiceImpl implements MusicService{

	Queries service = new Queries();
	
	@Override
	public List<MusicGroup> getMusicGroups(int limit, int offset, int minFoundingYear, int maxFoundingYear, long minAlbums, long maxAlbums, long minTracks, long maxTracks, long interactionCount, LinkedList<String> tags) {
		LinkedList<MusicGroup> groups = new LinkedList<>();
		for (String uri : service.getGroups(limit, offset, minFoundingYear, maxFoundingYear, minAlbums, maxAlbums, minTracks, maxTracks, interactionCount, tags)) {
			groups.add((MusicGroup)DataModelManager.getInstance().load(uri));
		}
		return groups;
	}

	@Override
	public MusicGroup getMusicGroup(String id) {
		MusicGroup group = (MusicGroup) DataModelManager.getInstance().load("http://is.fon.rs/music/MusicGroup/" + id);
		return group;
	}

	@Override
	public List<MusicAlbum> getAlbums(String groupID, int limit, int offset,long minTracks, long maxTracks, long interactionCount,LinkedList<String> tags) {
		LinkedList<MusicAlbum> albums = new LinkedList<>();
		for (String uri : service.getAlbums(groupID, limit, offset, minTracks, maxTracks, interactionCount, tags)) {
			albums.add((MusicAlbum)DataModelManager.getInstance().load(uri));
		}
		return albums;
	}

	@Override
	public List<MusicRecording> getRecordings(String groupID, int limit, int offset, long interactionCount,LinkedList<String> tags){
		LinkedList<MusicRecording> recordings = new LinkedList<>();
		for (String uri : service.getRecordings(groupID, limit, offset, interactionCount, tags)) {
			recordings.add((MusicRecording)DataModelManager.getInstance().load(uri));
		}
		return recordings;
	}

	@Override
	public List<MusicRecording> getAlbumRecordings(String albumid, int limit,
			int offset, long interactionCount, LinkedList<String> tags) {
		LinkedList<MusicRecording> recordings = new LinkedList<>();
		for (String uri : service.getAlbumRecordings(albumid, limit, offset, interactionCount, tags)) {
			recordings.add((MusicRecording)DataModelManager.getInstance().load(uri));
		}
		return recordings;
	}

	@Override
	public MusicAlbum getMusicAlbum(String id) {
		MusicAlbum album = (MusicAlbum) DataModelManager.getInstance().load("http://is.fon.rs/music/MusicAlbum/" + id);
		return album;
	}
}
